# coding:utf-8
import unittest

from api.depart import DepartAPI
from api.login import LoginAPI
from utils import common_assert


class TestDepartAPI(unittest.TestCase):
    Token=None
    Id=None

    def setUp(self) -> None:
        self.login_api=LoginAPI()
        self.depart_api=DepartAPI()
    def tearDown(self) -> None:
        pass
    def test01_login(self):
        response=self.login_api.login({"mobile":13800000002,"password":123456})
        TestDepartAPI.Token="Bearer "+response.json().get('data')
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')

    def test02_insert_depart(self):
        depart_info={"name":"企划部111","code":'0345987'}
        response=self.depart_api.insert_depart(TestDepartAPI.Token,depart_info)
        print(response.json())
        TestDepartAPI.Id=response.json().get('data').get('id')
        common_assert(self, response, 200, True, 10000, '操作成功')
    def test03_select_depart(self):
        response=self.depart_api.select_depart(TestDepartAPI.Id,TestDepartAPI.Token)
        print(response.json())
        common_assert(self,response,200,True,10000,"操作成功")

    def test04_update_depart(self):
        update_data={"name":"企划部1234567"}
        response=self.depart_api.update_depart(TestDepartAPI.Id,TestDepartAPI.Token,update_data)
        print(response.json())
        common_assert(self,response,200,True,10000,"操作成功")

    def test05_select_depart(self):
        response = self.depart_api.select_depart(TestDepartAPI.Id, TestDepartAPI.Token)
        print(response.json())
        common_assert(self, response, 200, True, 10000, "操作成功")
    def test06_delete_depart(self):
        response=self.depart_api.delete_depart(TestDepartAPI.Id,TestDepartAPI.Token)
        print(response.json())
        common_assert(self, response, 200, True, 10000, "操作成功")
